package com.woniuxy.light_smart.controller;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;

@RestController
@RequestMapping("/userlogin")
public class LoginCardController {
    public static HashMap<String, String> map = new HashMap<>();
    @Autowired
    HttpServletResponse response;
    @GetMapping("getCode")
    public void getCode() throws IOException{
        //利用hutool工具，生成验证码图片资源
        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200,100,4,5);
        // 获取验证码字符
        String code = captcha.getCode();
        System.out.println("验证码为"+code);

        String uuid = UUID.randomUUID().toString();
        map.put(uuid,code);

        response.setHeader("uuid", uuid);

        captcha.write(response.getOutputStream());
    }

}
